package com.runjian.rundo.iot.agent.common.network.tcp.parser;

import io.netty.handler.codec.ByteToMessageDecoder;
import lombok.extern.slf4j.Slf4j;

/**
 * 自定义解码器
 *
 * @author CaoQingHua
 */
@Slf4j
public class CustomPayloadParser implements PayloadParser {

    private final Class<? extends ByteToMessageDecoder> clz;

    public CustomPayloadParser(Class<? extends ByteToMessageDecoder> clz) {
        this.clz = clz;
    }

    @Override
    public ByteToMessageDecoder getParser() {
        try {
            return clz.newInstance();
        } catch (InstantiationException | IllegalAccessException e) {
            log.error("实例化解码器失败：{}", e.toString());
        }
        return null;
    }
}
